import {
	getShopData,
	getShopInfoData
} from "../../api/business";
export default {
	namespaced: true,
	state: {
		shops: [], //商家列表
		shopInfo: {} //商家信息
	},
	mutations: {
		//设置商铺列表
		["SET_SHOPS"](state, payload) {
			console.log(payload.shops)
			state.shops = payload.shops;
		},
		// 设置商铺分页数据
		["SET_SHOPS_PAGE"](state, payload) {
			state.shops.push(...payload.shops)
		},
		//设置商家信息
		["SET_SHOP_INFO"](state, payload) {
			state.shopInfo = payload.shopInfo;
		}


	},
	actions: {
		//显示首页商家列表
		getShop(conText, payload) {
			getShopData(payload).then(res => {
				console.log(res)
				if (res.code == 200) {
					conText.commit("SET_SHOPS", {
						shops: res.data
					});
					if (payload.success) {
						payload.success(res.pageinfo.pagenum)
					}
					// 判断完成状态
					if (payload.complete) {
						payload.complete()
					}
				}
			})
		},
		//显示首页分页商家数据
		getShopPage(context, payload) {
			getShopData(payload).then(res => {
				if (res.code == 200) {
					context.commit("SET_SHOPS_PAGE", {
						shops: res.data
					})
				}
			})
		},
		//取得商家信息
		getShopInfo(conText, payload) {
			getShopInfoData(payload).then(res => {
				if (res.code == 200) {
					conText.commit("SET_SHOP_INFO", {
						shopInfo: res.data
					});
				}
			})
		}
	}
}